package com.test.prolenders.view_prolenders.process_widget_prolenders;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.test.prolenders.R;
import com.test.prolenders.base_prolenders.BaseProcessWidgetManager_prolenders;
import com.test.prolenders.bean_prolenders.process_prolenders.ProcessInfo_Data_prolenders;
import com.test.prolenders.util_prolenders.http_prolenders.HttpUtil_prolenders;


public class GenderSelectViewManager_prolenders extends BaseProcessWidgetManager_prolenders {

    private TextView titleTv;
    private TextView maleTv, femaleTv;

    private boolean isMale = true;

    public GenderSelectViewManager_prolenders(View view, ProcessInfo_Data_prolenders data, String pageTag){
        super(view,data,pageTag);
    }

    @Override
    protected void init(){

        titleTv = mView.findViewById(R.id.vpgs_tv_title);
        maleTv = mView.findViewById(R.id.vpgs_tv_male);
        femaleTv = mView.findViewById(R.id.vpgs_tv_female);

        maleTv.setOnClickListener(v -> setGender(true));
        femaleTv.setOnClickListener(v -> setGender(false));

        setTitle(mData.getTitle());

    }

    @Override
    public boolean checkInput() {
        return true;
    }

    @Override
    public String getInput() {
        return isMale ? "MALE":"FEMALE";
    }

    public void setGender(boolean isMale){
        this.isMale = isMale;
        if (isMale){
            maleTv.setBackgroundResource(R.drawable.bg_blue_t_rc24dp_border_blue_1dp_prolenders);
            maleTv.setTextColor(mView.getContext().getColor(R.color.blue_main_prolenders));
            femaleTv.setBackgroundResource(R.drawable.bg_gray_rc24dp_prolenders);
            femaleTv.setTextColor(Color.parseColor("#FF6E6E6E"));
        }else {
            maleTv.setBackgroundResource(R.drawable.bg_gray_rc24dp_prolenders);
            maleTv.setTextColor(Color.parseColor("#FF6E6E6E"));
            femaleTv.setBackgroundResource(R.drawable.bg_blue_t_rc24dp_border_blue_1dp_prolenders);
            femaleTv.setTextColor(Color.parseColor("#FF6E6E6E"));
        }

        HttpUtil_prolenders.getInstance().saveBuriedPoint(page,mData.getParamName().toUpperCase()+"_CLICK",getInput());
    }

    public void setTitle(String title){
        if (TextUtils.isEmpty(title)) titleTv.setVisibility(GONE);
        else {
            titleTv.setVisibility(VISIBLE);
            titleTv.setText(title);
        }
    }

}
